package com.deductive.web.disposition.special;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deductive.common.core.controller.BaseController;
import com.deductive.common.core.domain.AjaxResult;
import com.deductive.common.core.page.TableDataInfo;
import com.deductive.domain.special.SpecialSeaport;
import com.deductive.service.special.SpecialSeaportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("specialSeaport")
@Api(tags = "专题-港口")
public class SpecialSeaportController extends BaseController {


    /**
     * 服务对象
     */
    @Resource
    private SpecialSeaportService specialSeaportService;

    /**
     * 分页查询所有数据
     *
     * @param specialSeaport 查询实体
     * @return 所有数据
     */
    @GetMapping("/pageQuery")
    @ApiOperation("分页查询")
    public TableDataInfo selectAll(SpecialSeaport specialSeaport) {
        startPage();
        List<SpecialSeaport> list = this.specialSeaportService.list(new QueryWrapper<>(specialSeaport));
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(this.specialSeaportService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param specialSeaport 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("新增数据")
    public AjaxResult insert(@RequestBody SpecialSeaport specialSeaport) {
        return success(this.specialSeaportService.save(specialSeaport));
    }

    /**
     * 修改数据
     *
     * @param specialSeaport 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation("修改数据")
    public AjaxResult update(@RequestBody SpecialSeaport specialSeaport) {
        return success(this.specialSeaportService.updateById(specialSeaport));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation("删除数据")
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return success(this.specialSeaportService.removeByIds(idList));
    }

}
